<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>execContentsAction test</title>
<style>
    div.t {
        border: 1px solid green;
        padding: 10px;
        margin: 5px;
    }
</style>
</head>
<body>
<button id="t">test</button>
<div class='t' id="d1">

    <div id="d1_1" class='t'>
        <div id="d1_1_1" class='t'>
            <div id="d1_1_1_1" class='t'>

            </div>
            <div id="d1_1_1_2" class='t'>
                <div id="d1_1_1_2_1" class='t'>

                </div>
                <div id="d1_1_1_2_2" class='t'>

                </div>
                <div id="d1_1_1_2_3" class='t'>

                </div>
            </div>
            <div id="d1_1_1_3" class='t'>

            </div>
        </div>
        <div id="d1_1_2" class='t'>
            <div id="d1_1_2_1" class='t'>

            </div>
        </div>
        <div id="d1_1_3" class='t'>
            <div id="d1_1_3_1" class='t'>
                <div id="d1_1_3_1_1" class='t'>

                </div>
                <div id="d1_1_3_1_2" class='t'>

                    <div id="d1_1_3_1_2_1" class='t'>

                    </div>

                    <div id="d1_1_3_1_2_2" class='t'>

                    </div>

                    <div id="d1_1_3_1_2_3" class='t'>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="d1_2" class='t'>

    </div>
</div>
</body>
<script src="http://a.tbcdn.cn/s/kissy/1.1.5/kissy-min.js"></script>
<script src="../src/editor.js"></script>
<script src="../src/core/utils.js"></script>
<script src="../src/core/focusmanager.js"></script>
<script src="../src/core/definition.js"></script>
<script src="../src/core/dtd.js"></script>
<script src="../src/core/dom.js"></script>
<script src="../src/core/elementpath.js"></script>
<script src="../src/core/walker.js"></script>
<script src="../src/core/range.js"></script>
<script src="../src/core/domiterator.js"></script>
<script src="../src/core/selection.js"></script>
<script src="../src/core/styles.js"></script>

<script>
    function assert(c, t) {
        if (!c) KISSY.log(t);
    }

    var ids = ["d1",
        "d1_1",
        "d1_1_1",
        "d1_1_1_1",
        "d1_1_1_2",
        "d1_1_1_2_1",
        "d1_1_3",
        "d1_1_3_1",
        "d1_1_3_1_2",
        "d1_2"];

    KISSY.ready(function(S) {

        S.one("#t").on("click", function() {
            var KE = S.Editor;
            var range = new KE.Range(document);
            range.setStartBefore(S.one("#d1_1_1_2_2"));

            range.setEndAfter(S.one("#d1_1_3_1_2_3"));
            var docFrag = document.createDocumentFragment();
            //startContainer 到 根 都不会删除 ，只删除 startContainer 的子节点
            //startContainer - endContainer 但中间的节点都会删除
            range.execContentsAction(0, docFrag);

            var divs = S.all("div.t");
            assert(divs.length == ids.length,
                    "数目不对 : " + divs.length + " : " + ids.length);
            var dids = [];
            for (var i = 0; i < divs.length; i++) {
                var id = divs[i].id;
                dids.push(id);
                assert(S.inArray(id, ids), id + " error");
            }
            S.log("verify 2");

            for (var i = 0; i < ids.length; i++) {
                var id = ids[i];
                assert(S.inArray(id, dids), id + " error");
            }

        });

    });


</script>

</html>